<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>二手车仓库</title>
    <!--加载layui的css样式-->
    <link rel="stylesheet" href="/aaa/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/aaa/layuiadmin/style/admin.css" media="all">
    <!--照片栏高度-->
    <style>
        .layui-table-cell {
            height: 80px;
            line-height: 80px;

        }

    </style>

</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <!--搜索菜单栏-->
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <!--搜索条件-->
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">手机号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="telphone" id="telephone" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">车型号：</label>
                    <div class="layui-input-block">
                        <select name="goodsname" id="goodsname" required placeholder="请选择型号" autocomplete="off"></select>
                    </div>
                </div>
                <!--<div class="layui-inline">-->
                    <!--<label class="layui-form-label">车型号：</label>-->
                    <!--<div class="layui-input-block">-->
                        <!--<select  class="form-control input-sm" name="goodsname" id="" lay-filter="goodsname" aria-invalid="false">-->
                            <!--<option value="">请选择车辆型号</option>-->
                        <!--</select>-->
                    <!--</div>-->
                <!--</div>-->



                <!--搜索按钮-->
                <div class="layui-inline">
                    <button id="secondcarentrepot-searchbtn" class="layui-btn layuiadmin-btn-admin" lay-submit
                            lay-filter="LAY-user-back-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>



                <!--添加新的二手车到二手车仓库-->
                <div class="layui-button">
                    <button id="newsecondcar" class="layui-btn layui-btn-nomal">
                        <i class="layui-icon  layuiadmin-button-btn">添加二手车代卖信息</i>
                    </button>
                </div>
            </div>
        </div>
        <!--查询出的信息栏-->
        <div class="layui-card-body">
            <table class="layui-hide" id="secondcarentrepot" lay-filter="secondcarentrepot-filter"></table>
            <!--前缀编号-->
            <script type="text/html" id="addList">
                {{d.LAY_TABLE_INDEX+1}}
            </script>
            <!--layui的js包-->
            <script src="/aaa/layuiadmin/layui/layui.js"></script>
            <!--操作按键-->
            <script type="text/html" id="secondcarentrepot-bar">
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="secondcarentrepot-sell">确认卖出</a>
                <a class="layui-btn  layui-btn-xs" lay-event="secondcarentrepot-desc">详情</a>
            </script>
        </div>
    </div>
</div>
<!--弹出层仓库中在售的二手车的详情-------------------------------------------------------------------------------------------------->
<div class="x-body" style="display:none;" id="secondcar-layer">
    <!--form表单展示二手车在售的详情-->
    <form class="layui-form" id="newform" lay-filter="detailmessage">
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">二手车详细介绍：</label>
            <div class="layui-input-block">
                <textarea  class="layui-textarea" name="secondcarentrepot-desc" id="secondcarentrepot-desc"></textarea>
            </div>
        </div>
    </form>
</div>
<!--弹出层新增二手车仓库中的二手车信息-------------------------------------------------------------------------------------------------->
<div class="x-body" style="display:none;" id="newsecondcar-layer">
    <!--form表单填入二手车出售的详情-->
    <form class="layui-form" id="addform" lay-filter="detailmessage">
        <div class="layui-form-item">
            <label class="layui-form-label">门店：</label>
            <div class="layui-input-inline">
                <!--<input type="text" name="newsecondcar-school" id="" required lay-verify="required"-->
                       <!--placeholder="" autocomplete="off" class="layui-input" >-->
                <select name="schoolid" id="newsecondcar-school"   autocomplete="off" lay-filter="type"></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">车主手机号：</label>
            <div class="layui-input-inline">
                <input type="text" name="telephone" id="newsecondcar-telephone" required lay-verify="required"
                       placeholder="" autocomplete="off" class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电车型号：</label>
            <div class="layui-input-inline">

                <select name="goodsname" id="newsecondcar-goodsname" required placeholder="请选择型号" autocomplete="off"></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">出厂码：</label>
            <div class="layui-input-inline">
                <input type="text" name="carcode" id="newsecondcar-carcode" required lay-verify="required"
                       placeholder="" autocomplete="off" class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">卖价：</label>
            <div class="layui-input-inline">
                <input type="text" name="carcost" id="newsecondcar-carcost" required lay-verify="required"
                       placeholder="" autocomplete="off" class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">二手车详细介绍：</label>
            <div class="layui-input-block">
                <textarea  class="layui-textarea" name="desc" id="newsecondcar-desc"></textarea>
            </div>
        </div>
        <!--保存新的二手车仓库的信息-->
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="newsecondcar-layer">确认添加</button>
            </div>
        </div>
    </form>
</div>

<!--自定义模板区分是否认证-->
<script type="text/html" id="state">
    {{#if (d.verifystate == 0) { }}
    <span>未认证</span>
    {{# }else if(d.verifystate == 1){ }}
    <span>认证</span>
    {{# } }}
</script>
<script th:inline="none">
    layui.use(['table', 'laytpl', 'form'], function () {
        var table = layui.table;
        var laytpl = layui.laytpl;
        var form = layui.form;
        var $ = layui.$;
        table.render({
            //连接搜索栏
            elem: '#secondcarentrepot',
            height: 400,
            //跳转的地址信息
            url: '/aaa/SecondCarEntrepotController/GetSecondCarEntrepotMessage',
            //分页功能
            page: true,
            //列表中所查询的信息
            cols: [
                [
                    {field: 'add', title: '编号', align: 'center', templet: '#addList', width: 50},
                    {field: 'school', title: '学校', align: 'center',sort:true},
                    {field: 'telephone', title: '用户手机号', align: 'center'},
                    {field: 'goodsname', title: '电车型号', align: 'center',sort:true},
                    {field: 'carcode', title: '出厂码', align: 'center'},
                    {field: 'carcost', title: '卖价', align: 'center'},
                    {title: '操作', toolbar: '#secondcarentrepot-bar', align: 'center'},
                ]
            ],
            

        });

        //搜索框点击事件-----------------------------------------------------------------------------------------------
        $('#secondcarentrepot-searchbtn').click(function () {
            table.reload('secondcarentrepot', {
                url: '/aaa/SecondCarEntrepotController/GetSecondCarEntrepotMessage',
                where: {
                    telephone: $("#telephone").val(),
                    goodsname: $("#goodsname").val()
                } //设定异步数据接口的额外参数
                //,height: 300
            });
        })
        //所有按钮点击事件-----------------------------------------------------------------------------------------------
        //监控数据表格
        table.on('tool(secondcarentrepot-filter)', function (obj) {
            var data = obj.data;
            //详情按钮触发的事件----------------------------------------
            //查询对应的二手车详细信息----------------------------------------------
            if (obj.event === 'secondcarentrepot-desc') {
                //查询对应的二手车认证信息表单内容
                $.post({
                    //后台地址
                    url: '/aaa/SecondCarEntrepotController/GetSecondCarDescribe',
                    //传入后台的内容
                    data: {
                        carcode: data.carcode,
                        telephone: data.telephone
                    },
                    //成功返回的参数
                }, function (data) {
                    //alert(data[0].telephone);
                    $("#secondcarentrepot-desc").val(data);

                });
                //加载数据完毕后打开表单
                secondcarentrepotlayer = layer.open({
                    type: 1,
                    title: '二手车详细介绍',
                    shade: [0.3, '#393D49'],
                    maxmin: false,
                    shadeClose: false,
                    area: ['893px', '550px'],
                    //打开的弹出层
                    content: $('#secondcar-layer')
                });


            } else if (obj.event === 'secondcarentrepot-sell') {
                layer.confirm('确认电话为' + data.telephone + '的用户的二手车出厂码为'+data.carcode+"卖出吗？", function (index) {
                    $.post("/aaa/SecondCarEntrepotController/SellSecondCar", {
                        "carcode": data.carcode,
                        "telephone": data.telephone
                    }, function (res) {
                        if (res.code==100){
                            layer.closeAll();
                            layer.msg('已将出厂码为'+data.carcode+'原车主为'+data.telephone+'的电车确认卖出',{icon:1,time:3000});
                            location.reload();
                        }else{
                            layer.msg('失败出现错误',{icon:1,time:3000});
                        }


                    });



                });
            }



        });


        //新增二手车仓库信息
        $(document).on('click','#newsecondcar',function(){
            layer.msg('hello');
            cartransferlayer = layer.open({
                type: 1,
                title: '新增二手车信息',
                shade: [0.3, '#393D49'],
                maxmin: false,
                shadeClose: false,
                area: ['893px', '550px'],
                //打开的弹出层
                content: $('#newsecondcar-layer')
            });
        });

        //动态获取门店下拉框
        $.ajax({
            type : "post",
            url : "/aaa/SecondCarEntrepotController/Getschool",
            dataType : "json",
            async : false,
            success : function(data) {
                // console.log(data);
                for(var i=0;i<data.length;i++){
                    // alert(data[i].school)
                    var html="";
                    html = "<option value='"+data[i].id+"'>"+data[i].school+"</option>";
                    $("#newsecondcar-school").append(html);
                }

            },
            error : function(result, status) {
            }
        });
        //动态获取电车型号
        $.ajax({
            type : "post",
            url : "/aaa/SecondCarEntrepotController/Getgoodsname",
            dataType : "json",
            async : false,
            success : function(data) {
                // console.log(data);
                for(var i=0;i<data.length;i++){
                    var html="";
                    html = "<option value='"+data[i].goodsname+"'>"+data[i].goodsname+"</option>";
                    $("#newsecondcar-goodsname").append(html);
                    $("#goodsname").append(html);
                }
            },
            error : function(result, status) {
            }
        });
        //form表单监控
        form.render();
        //二手车添加确认按钮
        //form表单监控，监控提交按钮
        form.on('submit(newsecondcar-layer)', function (data) {
            var param = data.field;//定义临时变量获取表单提交过来的数据，非json格式
            console.log(param);
                $.ajax({
                    url: "/aaa/SecondCarEntrepotController/SetNewSecondCar",
                    method: 'post',//method请求方式，get或者post
                    dataType: 'json',//预期服务器返回的数据类型
                    data: param,//表格数据序列化
                    success: function (res) {//res为相应体,function为回数
                        if (res.code==100) {
                            layer.closeAll();
                            layer.msg('已添加该车辆信息',{icon:1,time:3000});
                            location.reload();
                        }else{
                            layer.msg('该车辆信息及车主信息错误',{icon:1,time:3000});
                        }
                    }

                });
                return false;
        });

    });
</script>
</body>
</html>